using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MeleeWeapon : Weapon
{
    public List<EnemyControl> enemiesInRange;
    public override void Fire()
    {
        GameMgr.Get<IPlayerManager>().Player.Slash();
        //Debug.Log(enemiesInRange.Count);
        if(enemiesInRange.Count>0)
        {
            AudioControl.Instance.PlaySound(name+"_Hit",1);
        }
        for(int i=enemiesInRange.Count-1;i>=0;i--)
        {
            GameMgr.Get<IEnemyManager>().Damage(enemiesInRange[i], damage,
            new DamageArgs() { directionAngle = transform.eulerAngles.z + 90, source = transform.position });
        }

        AudioControl.Instance.PlaySound(name,0.5f);
    }

    private void Awake()
    {
        enemiesInRange = new List<EnemyControl>();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.GetComponent<EnemyControl>())
        {
            enemiesInRange.Add(collision.gameObject.GetComponent<EnemyControl>());
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.gameObject.GetComponent<EnemyControl>())
        {
            enemiesInRange.Remove(collision.gameObject.GetComponent<EnemyControl>());
        }
    }
}
